package com.ruoyi.clf.scheduler;

import com.ruoyi.clf.domain.MerchantAggregationResult;
import com.ruoyi.clf.mapper.EvaluateMapper;
import com.ruoyi.clf.service.impl.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class NightlyTask {




    // cron表达式：秒 分 时 日 月 周


    @Scheduled(cron = "0 0 2 * * ?") // 每天凌晨2点执行
    public void performNightlyTasks() throws Exception {
//        每天晚上两点将评分计算汇聚到商户的评分上
        updateMerchantRating();
//        每天晚上两点将收支计算汇聚到商户的收支上
        updateMerchantIncome();


    }

//    每天晚上两点将评分计算汇聚到商户的评分上

    @Autowired
    private EvaluateService evaluateService;


    public void updateMerchantRating() throws Exception {
        // 调用服务层方法执行评分计算
        List<MerchantAggregationResult> merchantAggregationResults = evaluateService.testMerchantAggregation();
//        循环遍历merchantAggregationResults
        for (MerchantAggregationResult merchantAggregationResult : merchantAggregationResults) {
//            在商家表上循环遍历，将评分更新到商家表上


        }
        System.out.println("评分");
    }

//    每天晚上两点将收支计算汇聚到商户的收支上
    public void updateMerchantIncome() {
        System.out.println("收支");
    }

}
